package com.example.emergency;





import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class RestorePhno extends Activity{
	static SQLiteDatabase db=null;
	private DBHandler mDbHelper;

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.restoreemergencyno);
		mDbHelper=new DBHandler(this);
		 mDbHelper.open();
		
		final MediaPlayer mp=MediaPlayer.create(this, R.raw.sound4);
		Button restorebutton=(Button) findViewById(R.id.restorephnobutton);
		
		restorebutton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				EditText edit =  (EditText) findViewById(R.id.textphno);
				String phno=edit.getText().toString();
				mDbHelper.updateNote(1, "1", phno);
				mp.start();
				AlertDialog.Builder builder=new AlertDialog.Builder(RestorePhno.this);
				builder.setMessage("Your phno was restored successfully");
				builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						Intent i=new Intent(RestorePhno.this,EmergencyfirstAid.class);
						startActivity(i);
						mp.start();
					}
				});
				
				builder.create();
				builder.show();
				
				/*ContentValues initialValues = new ContentValues();//insert
		        initialValues.put(dbhandler.KEY_KEY, "1");
		        initialValues.put(dbhandler.KEY_PHNO, phno);
		       db.insert("Emg_phno", null, initialValues);*/
				//long a=mDbHelper.createNote("1", phno);
				
				/*
				ContentValues args = new ContentValues();
		        args.put(dbhandler.KEY_KEY, "1");
		        args.put(dbhandler.KEY_PHNO, phno);
		        int rowId=1;
		        String strFilter = null; 
		        strFilter = " id=" + dbhandler.KEY_ID;*/
		        

		       // db.update("Emg_phno", args, strFilter, null);
				
				//setContentView(R.layout.restoresuccess);
				
			}
		});
	        
		
	}
	
	/*public String fetchphno(int mRowId)
	{
		mDbHelper=new DBHandler(this);
		 mDbHelper.open();
		 String phno="";
	      
		 Cursor mCursor=mDbHelper.fetchNote(1);
	      
	       startManagingCursor(mCursor);
	       StringBuilder builder = new StringBuilder(); //we create a builder to aggregate a result
	       
	       while(mCursor.moveToNext())
	       {
	              // String name = mCursor.getString(1);  
	               phno = mCursor.getString(1);
	               
	       }
		 return phno;
	}*/
}
